function getModel() {
  let modalDom = PopManager.modalDom;
  if (modalDom) {
    return modalDom;
  } else {
    modalDom = document.createElement('div');
    PopManager.modalDom = modalDom;
  }
  return modalDom;
}
const PopManager = {
  zIndex: 2000,
  nextzIndex() {
    return this.zIndex++;
  },
  openModal(dom, zIndex) {
    const modalDom = getModel();
    modalDom.classList.add('v-modal');
    modalDom.classList.add('v-modal-enter');
    let parent = dom.parentNode || document.body;
    setTimeout(() => {
      if (modalDom.classList.contains('v-modal-enter')) modalDom.classList.remove('v-modal-enter');
    }, 500);
    if (zIndex) {
      modalDom.style.zIndex = zIndex;
    }
    parent.appendChild(modalDom);
  },
  closeModal() {
    let modalDom = getModel();
    modalDom.classList.add('v-modal-leave');
    setTimeout(() => {
      if (modalDom.classList.contains('v-modal-leave')) modalDom.classList.remove('v-modal-leave');
      if (modalDom.parentNode) modalDom.parentNode.removeChild(modalDom);
    }, 400);
  }
};
export default PopManager;
export { PopManager };
